package com.dongzili.postgresql.common.mybatisplus;

import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.dongzili.postgresql.common.mybatisplus.postgresql.SqlBacktickRemoverInterceptor;
import com.dongzili.postgresql.common.mybatisplus.postgresql.TimestampTzToLocalDateConverter;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置分页插件
 *
 */
@Configuration
@MapperScan("com.dongzili.postgresql.*")
public class MybatisPlusConfig {


    /**
     * 注册SQL拦截器（去除反引号）
     */
    @Bean
    public SqlBacktickRemoverInterceptor sqlBacktickRemoverInterceptor() {
        return new SqlBacktickRemoverInterceptor();
    }
    @Bean
    public ConfigurationCustomizer configurationCustomizer() {
        return configuration -> {
            // 注册全局类型转换器
            configuration.getTypeHandlerRegistry()
                    .register(TimestampTzToLocalDateConverter.class);
        };
    }

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        CustomizePaginationInterceptor customizePaginationInterceptor = new CustomizePaginationInterceptor();
        interceptor.addInnerInterceptor(customizePaginationInterceptor);
        return interceptor;
    }

//    @Bean
//    public ConfigurationCustomizer configurationCustomizer() {
//        return configuration -> {
//            configuration.addInterceptor(new PostgreSqlFieldNameInterceptor());
//        };
//    }


}

